package com.yh.zz_hlj.modules.adatper;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yh.zz_hlj.R;
import com.yh.zz_hlj.modules.bean.CardZX;
import com.yh.zz_hlj.modules.recycleviewutil.onMoveAndSwipedListener;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * =========================
 * 版权所有，违法必究
 * 作者：john
 * <p>
 * 工程：ZZVComApp
 * <p>
 * 文件名：InOrOutStockAdapter
 * <p>
 * 创建时间：2017.06.19.13:36
 * *****************************
 */
public class ZXStockAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements onMoveAndSwipedListener {

    private Context ctx;
    private ArrayList<CardZX> datas;

    public ZXStockAdapter(Context ctx, ArrayList<CardZX> datas) {
        this.ctx = ctx;
        this.datas = datas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(ctx).inflate(R.layout.item_mat_zx, parent,
                false);
        return new MatViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MatViewHolder) {
            intDataView((MatViewHolder) holder, position);
        }
    }

    //初始化数据 赋值
    private void intDataView(MatViewHolder holder, int position) {
        CardZX data = datas.get(position);
        holder.tvNum.setText(data.getFNumber());
        holder.tvNums.setText("盒号: " + (position + 1));
        holder.tvType.setText(data.getFType());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    @Override
    public boolean onItemMove(int fromPosition, int toPosition) {
        return false;
    }

    @Override
    public void onItemDismiss(int position) {
        datas.remove(position);
        notifyItemRemoved(position);
    }

    static class MatViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.tv_number)
        TextView tvNum;
        @InjectView(R.id.tv_num)
        TextView tvNums;
        @InjectView(R.id.tv_type)
        TextView tvType;

        public MatViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

}
